package com.csap.framework.oauth2.server.service.impl;

import com.csap.framework.annotation.apidoc.Description;
import com.csap.framework.oauth2.server.entity.PlatformEntity;
import com.csap.framework.oauth2.server.model.PlatformModel;
import com.csap.framework.oauth2.server.mybatis.PlatformMapper;
import com.csap.framework.oauth2.server.service.PlatformService;
import com.csap.framework.util.exception.ExceptionUtils;
import com.csap.mybatisplus.extension.service.impl.BaseCsapServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 平台
 * </p>
 *
 * @author yangchengfu
 * @dateTime 2021-07-25 23:51:30
 */
@Service
@Description(value = "平台ServiceImpl")
public class PlatformServiceImpl extends BaseCsapServiceImpl<PlatformMapper, PlatformEntity, PlatformModel, Long> implements PlatformService {

    @Cacheable(value = "${csap.token.token-name}:platform#86400", key = "#platform")
    @Override
    public PlatformModel findByCode(String platform) {
        return lambdaQuery()
                .select(PlatformEntity::getPlatform)
                .eq(PlatformEntity::getPlatform, platform)
                .oneOptional()
                .isNullThrow(i -> ExceptionUtils.mpe("平台不存在"))
                .transform(PlatformModel.class);
    }
}
